<template>
  <div class="shop-info" v-if="Object.keys(shopInfo).length != 0">
    <div class="shop-title">
      <img :src="shopInfo.logo" alt="logo" />
      <h2>{{shopInfo.name}}</h2>
    </div>
    <div class="shop-data">
      <div class="count">
        <div class="count-l">
          <!-- <p class="count-num">{{this.getCount(shopInfo.sells)}}</p> -->
          <p class="count-num">{{shopInfo.sells | sellCountFilter}}</p>
          <p class="count-name">总销量</p>
        </div>
        <div class="count-r">
          <p class="count-num">{{this.getCount(shopInfo.goodsCount)}}</p>
          <p class="count-name">全部宝贝</p>
        </div>
      </div>
      <div class="score">
        <div
          v-for="(item, index) in shopInfo.score"
          :key="index"
          class="bad score-item"
          :class="{'good': item.isBetter}"
        >
          <div class="desc">{{item.name}}</div>
          <div class="price">{{item.score}}</div>
          <div class="quality">
            <span :style="getBackground(item.isBetter)">{{item.score > 4.75 ? '高': '低'}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "shop-info",
  props: {
    shopInfo: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  filters: {
    sellCountFilter(value) {
      let result = value;
      if (value > 1000) {
        result = (result / 10000).toFixed(1) + "万";
      }
      return result;
    }
  },
  methods: {
    getCount(count) {
      return String(count).length > 4
        ? String(count)[0] + "." + String(count)[1] + "万"
        : count;
    },
    getBackground(flag) {
      return flag ? { background: "#ff8198" } : { background: "#509204" };
    }
  }
};
</script>

<style scoped>
.shop-info {
  background: #fff;
  color: #333;
  border-bottom: 10px solid #f6f6f6;
}
.shop-title {
  display: flex;
  align-items: center;
  padding: 10px 0 18px 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shop-title img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid #f6f6f6;
}
.shop-title h2 {
  padding-left: 10px;
  text-transform: uppercase;
}
.shop-data {
  display: flex;
  text-align: center;
}
.shop-data > div {
  flex: 1;
}
.count {
  display: flex;
  align-items: center;
  position: relative;
}
.count::after {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  top: 12.5%;
  width: 2px;
  height: 75%;
  background: #f6f6f6;
}
.count > div {
  flex: 1;
}
.count-num {
  font-size: 18px;
  margin-bottom: 5px;
}
.bad {
  color: #509204;
}
.good {
  color: var(--color-tint);
}
.score-item {
  display: flex;
}
.score-item > div {
  text-align: center;
  height: 26px;
  line-height: 26px;
}
.desc {
  flex: 3;
}
.score-item .price {
  flex: 1;
  text-align: left;
}
.quality {
  flex: 1;
}
.quality span {
  padding: 1px;
  color: #fff;
  background: #509204;
}
</style>